package com.hottv.meeting.videomeeting.module.agora.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hottv.meeting.videomeeting.R;
import com.hottv.meeting.videomeeting.common.MeetingConfig;
import com.hottv.meeting.videomeeting.module.agora.data.MsgItem;
import com.hottv.meeting.videomeeting.module.meeting.MeetingManager;

import java.util.List;

/**
 * Created by chengwenqiang on 2019/6/4.
 */

public class MsgAdapter extends BaseAdapter {

    private LayoutInflater mInflater;

    private List<MsgItem> mMsgList;
    public MsgAdapter(Context context, List<MsgItem> msgList) {
        super();
        this.mInflater = LayoutInflater.from(context);
        this.mMsgList = msgList;
    }

    public void setList(List<MsgItem> msgList) {
        this.mMsgList = msgList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mMsgList.size();
    }

    @Override
    public Object getItem(int position) {
        return mMsgList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MsgAdapter.ViewHolder holder = null;

        if (convertView == null) {

            holder = new MsgAdapter.ViewHolder();
            convertView = mInflater.inflate(R.layout.list_view_msg, null);
            holder.name = (TextView)convertView.findViewById(R.id.txt_name);
            holder.msg = (TextView)convertView.findViewById(R.id.txt_msg);

            convertView.setTag(holder);
        }else{
            holder = (MsgAdapter.ViewHolder)convertView.getTag();
        }

        String name = (String)mMsgList.get(position).name;
        Log.i(MeetingConfig.TAG,"MsgAdapter name:"+name);
        holder.name.setText(name);
        holder.msg.setText((String)mMsgList.get(position).msg);

        return convertView;
    }

    public final class ViewHolder{

        public TextView name;

        public TextView msg;
    }
}
